package com.bzy.blade_auth.config.stpInterface;

import cn.dev33.satoken.stp.StpInterface;
import com.alibaba.fastjson.JSON;
import com.bzy.blade_auth.mapper.JurisdictionMapper;
import com.bzy.bladeauthapi.entry.Jurisdiction;
import com.bzy.bladeauthapi.vo.QueryWrapperVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 自定义权限验证接口扩展
 */
@Component    // 保证此类被SpringBoot扫描，完成Sa-Token的自定义权限验证扩展
public class StpInterfaceImpl implements StpInterface {


    @Autowired
    private JurisdictionMapper userJurisdictionMapper;

    /**
     * @param loginId   用户的id;
     * @param loginType 用户的类型;
     * @return
     * 查询用户都有哪些权限的数据信息;
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        List<Jurisdiction> userJurisdictions = userJurisdictionMapper.selectList(QueryWrapperVO.getQueryWrapper(JSON.toJSONString
                (new QueryWrapperVO().eq("user_id", loginId).select("jurisdiction"))));

        List<String> collect = userJurisdictions.stream().map(Jurisdiction::getJurisdiction).collect(Collectors.toList());
        return collect;
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     * 返回一个角色的列表数据集合;
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return null;
    }
}














